package me.helllp.dake.generator.meta.core;

import com.squareup.javapoet.ParameterSpec;

import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 参数
 * 
 * @author 林晓明
 *
 */
@Getter
@Setter
public class SmartParameter {
	/**
	 * 类型信息
	 */
	private SmartType type;
	
	/**
	 * 名称
	 */
	private String name;
	
	/**
	 * 描述
	 */
	private String desc;

	private List<SmartAnnotation> annotations;

	public ParameterSpec.Builder builder() {
		return ParameterSpec.builder(type.build(), name)
				.addAnnotations(
						Optional.ofNullable(annotations).map(item -> {
							return item.stream().map(parameter -> parameter.builder().build()).collect(Collectors.toList());
		}).orElse(Collections.emptyList()));
	}
}
